﻿using System;
using System.Globalization;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace WorkGps
{
    public class GGAGPSParcer:IGPSParcer
    {
        public GPSData Parce(string[] data)
        {
            foreach (string elem in data)
            {
                elem.Replace(".", CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator);
            }
            GPSData gpsData = new GPSData();

            gpsData.time = new DateTime(
                       DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
                       Convert.ToInt32(data[1].Substring(0, 2)),
                       Convert.ToInt32(data[1].Substring(2, 2)),
                       Convert.ToInt32(data[1].Substring(4, 2)),
                       Convert.ToInt32(data[1].Substring(7, 2)) * 10);

            gpsData.lat = Convert.ToInt32(data[2].Substring(0, 2)) +
                Convert.ToDouble(data[2].Substring(2)) / 60;
            if (data[3] == "S")
                gpsData.lat = -gpsData.lat;
            gpsData.lon = Convert.ToInt32(data[4].Substring(0, 3)) +
                Convert.ToDouble(data[4].Substring(3)) / 60;
            if (data[5] == "W")
                gpsData.lon = -gpsData.lon;
            return gpsData;
        }
    }
}
